package com.controller;

import com.pojo.Order;
import com.pojo.Product;
import com.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

@Controller
public class UserController {
    @RequestMapping("/getUserId")
    public void getUserId(HttpServletRequest request) {
        //HttpServletRequest 是Servlet的请求对象
        String userid =request.getParameter("userid");
        System.out.println("userid="+userid);
    }
    @RequestMapping("/getUserName")
    public void getUserName(String name ,Integer id) {
        System.out.println("name="+name+" *** "+"id="+id);
    }
    @RequestMapping("/getUserNNNN")
    public void getUserNNNN(@RequestParam (value ="name",required = false,defaultValue = "itheima") String name) {
        System.out.println("name="+name);
    }
    //pojo绑定
    @RequestMapping("/registerUser")
    public void registerUser(User user) {
        String name =user.getName();
        String password =user.getPassword();
        System.out.println("name="+name);
        System.out.println("password="+password);
    }@RequestMapping("/findOrderWithuser")
    public void findOrderWithuser(User user) {
        String name = user.getName();
        String orderid = user .getOrder().getOrderid();
        System.out.println("name="+name);
        System.out.println("password="+orderid);
    }
    @RequestMapping("/showOrders")
    public void showOrder(User user) {

        List<Order> orders = user.getOrders();
        List<String> addressList =user.getAddress();
        System.out.println("订单");
        for (int i=0 ;i<orders.size();i++) {
            Order order = orders.get(i);
            String address = addressList.get(i);
            System.out.println("订单ID："+order.getOrderid());
            System.out.println("订单ID："+address);
        }
    }
    @RequestMapping("/orderInfo")
    public void orderInfo(Order order) {
        String orderid = order.getOrderid();
        HashMap<String, Product> orderInfo =order.getPriductinfo();
        Set<String> keys = orderInfo.keySet();
        System.out.println("订单Id："+orderid);
        System.out.println("订单信息");
        for (String key : keys) {
            Product product = orderInfo.get(key);
            String porid =product.getPorid();
            String proName = product.getProName();
            System.out.println(key+"类~"+"商品id"+porid+"商品名称"+proName);
        }
    }
}

